<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/8/6
  Time: 16:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>编辑科目</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="${AppPath}/css/font.css">
    <link rel="stylesheet" href="${AppPath}/css/index.css">
    <script type="text/javascript" src="${AppPath}/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${AppPath}/js/index.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->

</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form" id="form">
            <div class="layui-form-item">
                <input type="hidden" name="ctId" value="${id}">
                <label  class="layui-form-label">
                    <span class="x-red">*</span>班级名称
                </label>
                <div class="layui-input-inline">
                    <select name="classId" id="classId" onchange="classId()">

                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>选择班级名称
                </div>
                <label class="layui-form-label" id="classIdmsg">

                </label>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>科目名称
                </label>
                <div class="layui-input-inline">
                    <select name="courseId" id="courseId" onchange="courseId()">

                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>选择科目名称
                </div>
                <label class="layui-form-label" id="courseIdmsg">

                </label>
            </div>
            <div class="layui-form-item">
                <label  class="layui-form-label">
                    <span class="x-red">*</span>星期
                </label>
                <div class="layui-input-inline">
                    <select name="ctWeek" id="ctWeek" onchange="ctWeek()">

                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>选择星期
                </div>
                <label class="layui-form-label" id="ctWeekmsg">

                </label>
            </div>
            <%--<div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red">*</span>角色</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="like1[write]" lay-skin="primary" title="超级管理员" checked="">
                    <input type="checkbox" name="like1[read]" lay-skin="primary" title="编辑人员">
                    <input type="checkbox" name="like1[write]" lay-skin="primary" title="宣传人员" checked="">
                </div>
            </div>--%>
            <div class="layui-form-item">
                <label for="ctTime" class="layui-form-label">
                    <span class="x-red">*</span>第几节课
                </label>
                <div class="layui-input-inline">
                    <select name="ctTime" id="ctTime">

                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    课
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                </label>
                <button  class="layui-btn" type="button" lay-filter="add" lay-submit="" id="editBtn">
                    编辑
                </button>
            </div>
        </form>
    </div>
</div>
<script src="${AppPath}/js/jquery.js"></script>
<script>
    $(function(){

    //查找展示数据
        $.ajax({
            url:"${AppPath}/coursetable/findOne",
            data:{"id":${id}},
            type:"post",
            success: function(data){
                if(data.result){
                    layer.msg("查找信息成功",{time:2000,icon:6},function () {
                       /* 班级初始化*/
                        let op ='';
                        op += '<option value="0">请选择班级名称</option>';
                        $.each(data.classList,function(index,clazz){
                            if(data.coursetable.classId==clazz.classId){
                                op += '<option value="'+clazz.classId+'" selected>'+clazz.className+'</option>';
                            }else{
                                op += '<option value="'+clazz.classId+'">'+clazz.className+'</option>';
                            }
                        })
                        $("#classId").html(op);
                        pre();
                        /*科目初始化*/
                        let or ='';
                        or += '<option value="0">请选择科目名称</option>';
                        $.each(data.courseList,function(index,course){
                            if(data.coursetable.courseId==course.courseId){
                                or += '<option value="'+course.courseId+'" selected>'+course.courseName+'</option>';
                            }else{
                                or += '<option value="'+course.courseId+'">'+course.courseName+'</option>';
                            }
                        })
                        $("#courseId").html(or);
                        pre();
                        /*星期初始化*/
                        let weeks = ["星期一","星期二","星期三","星期四","星期五","星期六","星期日"];
                        let ow ='';
                        ow += '<option value="0">请选择科目名称</option>';
                        $.each(weeks,function (index,week) {
                            if(data.coursetable.ctWeek==(index+1)){
                                ow += '<option value="'+(index+1)+'" selected>'+week+'</option>';
                            }else{
                                ow += '<option value="'+(index+1)+'">'+week+'</option>';
                            }
                        })
                        $("#ctWeek").html(ow);
                        pre();

                        /* 第几节课*/
                        let times = ['第一节','第二节','第三节','第四节'];
                        let to='';
                        to += '<option value="0">请选择第几节课</option>';
                        $.each(times,function (index,time) {
                            if((index+1)==data.coursetable.ctTime){
                                to += '<option value="'+(index+1)+'" selected>'+time+'</option>';
                            }else {
                                to += '<option value="'+(index+1)+'">'+time+'</option>';
                            }
                        })
                        $("#ctTime").html(to);
                        pre();
                    })
                }else {
                    layer.msg("查找信息失败！",{time:2000,icon:5,shift:6});
                }
            }
        })

    //监听提交
        $("#editBtn").click(function(){
            if(checkmsg()){
                $.ajax({
                    url:"${AppPath}/coursetable/updateById",
                    data:$("#form").serialize(),
                    type:"post",
                    success: function(data){
                        if(data.result){
                            layer.msg("编辑成功",{time:2000,icon:6},function () {
                                //关闭当前frame
                                xadmin.close();
                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                            })
                        }else{
                            layer.msg("编辑失败",{time:2000,icon:5,shift:6});
                        }
                    }
                })
            }
        })


})


/*渲染*/
function pre(){
    layui.use(['laydate','form'], function(){
        var laydate = layui.laydate;
        var  form = layui.form;
        form.render();
        // 监听全选
        form.on('checkbox(checkall)', function(data){

            if(data.elem.checked){
                $('tbody input').prop('checked',true);
            }else{
                $('tbody input').prop('checked',false);
            }
            form.render('checkbox');
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });
        form.render();
    });
}

    /*表单校验*/
    function checkmsg() {
        return classId()&&courseId()&&ctWeek();
    }

    function  classId(){
        let classId = $("#classId").val();
        let msg = "<font color='red'>科目不能为空</font>";
        let flag=false;
        if (classId!=null&&classId!=0) {
            msg = "<font color='green'>ok</font>";
            flag=true;
        }
        $("#classIdmsg").html(msg);
        return flag;
    }
    function  courseId(){
        let courseId = $("#courseId").val();
        let msg = "<font color='red'>科目属性不能为空</font>";
        let flag=false;
        if (courseId!=null&&courseId!=0) {
            msg = "<font color='green'>ok</font>";
            flag=true;
        }
        $("#courseIdmsg").html(msg);
        return flag;
    }
    function  ctWeek(){
        let ctWeek = $("#ctWeek").val();
        let msg = "<font color='red'>开课时间不能为空</font>";
        let flag=false;
        if (ctWeek!=null&&ctWeek!=0) {
            msg = "<font color='green'>ok</font>";
            flag=true;
        }
        $("#ctWeekmsg").html(msg);
        return flag;
    }
</script>
<script>var _hmt = _hmt || []; (function() {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
})();</script>
</body>

</html>

